function texte_init() 
{
	clicked_window = false
	clicked=false
	clicked2 = false
	for (var i = 26 ; i <= 53 ; i ++)
		svgdoc.getElementById("popup" + i.toString()).firstChild.data = popup_message[i]
	getDataFile("fonts/list_fonts.txt",callbackLG)
	text_popup = true
}

function initialise_texte()
{
	var police = "default"
	var taille = 8
	var style = "normal"
	var graisse = "normal"
	var espace_lettre = "0"
	var espace_mot = "0"
	var espace = "0"
	var direction = "ltr"
	var sens = "lr-tb"
	var horizontale = "0"
	var verticale = "0"
	var disposition = "normal"
	var decoration = "none"
	if ((active_field != "")&&(active_field.indexOf("text") == 0))
	{
		var etiq = active_field.substring(0 , 4) + "rect" + active_field.substring(4 , active_field.length)
		var test = svgdoc.getElementById(etiq)
		if (test.hasAttribute("font-family"))
			police = test.getAttribute("font-family")
		if (test.hasAttribute("font-size"))
			taille = test.getAttribute("font-size")
		if (taille > 50)
			taille = 50
		if (test.hasAttribute("font-style"))
			style = test.getAttribute("font-style")
		if (test.hasAttribute("font-weight"))
			graisse = test.getAttribute("font-weight")
		if (test.hasAttribute("letter-spacing"))
			espace_lettre = test.getAttribute("letter-spacing")
		if (test.hasAttribute("word-spacing"))
			espace_mot = test.getAttribute("word-spacing")
		if (test.hasAttribute("kerning"))
			espace = test.getAttribute("kerning")
		if (test.hasAttribute("direction"))
			direction = test.getAttribute("direction")
		if (test.hasAttribute("writing-mode"))
			sens = test.getAttribute("writing-mode")
		if (test.hasAttribute("glyph-orientation-horizontal"))
			horizontale = test.getAttribute("glyph-orientation-horizontal")
		if (test.hasAttribute("glyph-orientation-vertical"))
			verticale = test.getAttribute("glyph-orientation-vertical")
		if (test.hasAttribute("font-stretch"))
			disposition = test.getAttribute("font-stretch")
		if (test.hasAttribute("text-decoration"))
			decoration = test.getAttribute("text-decoration")
	}
	if (style == "normal")
		svgdoc.getElementById("font-style").setAttribute("cx" , "100")
	else
		svgdoc.getElementById("font-style").setAttribute("cx" , "160")
	if (graisse == "normal")
		svgdoc.getElementById("font-weight").setAttribute("cx" , "100")
	else
		svgdoc.getElementById("font-weight").setAttribute("cx" , "160")
	if (direction == "ltr")
		svgdoc.getElementById("direction").setAttribute("cx" , "100")
	else
		svgdoc.getElementById("direction").setAttribute("cx" , "140")
	switch(sens)
	{
		case "lr-tb" : var x_check = 100; break;
		case "rl-tb" : var x_check = 140; break;
		case "tb-rl" : var x_check = 180; break;
	}
	svgdoc.getElementById("writing-mode").setAttribute("cx" , x_check)
	switch(horizontale)
	{
		case "0" : var x_check = 100; break;
		case "90" : var x_check = 140; break;
		case "180" : var x_check = 180; break;
		case "270" : var x_check = 220; break;
	}
	svgdoc.getElementById("glyph-orientation-horizontal").setAttribute("cx" , x_check)
	switch(verticale)
	{
		case "0" : var x_check = 100; break;
		case "90" : var x_check = 140; break;
		case "180" : var x_check = 180; break;
		case "270" : var x_check = 220; break;
	}
	svgdoc.getElementById("glyph-orientation-vertical").setAttribute("cx" , x_check)
	switch(disposition)
	{
		case "normal" : var x_check = 100; break;
		case "expanded" : var x_check = 160; break;
		case "condensed" : var x_check = 220; break;
	}
	svgdoc.getElementById("font-stretch").setAttribute("cx" , x_check)
	switch(decoration)
	{
		case "none" : var x_check = 100; break;
		case "underline" : var x_check = 160; break;
		case "overline" : var x_check = 230; break;
		case "line-through" : var x_check = 300; break;
	}
	svgdoc.getElementById("text-decoration").setAttribute("cx" , x_check)
	svgdoc.getElementById("font-size_curseur").setAttribute("width" , 2 * taille )
	svgdoc.getElementById("letter-spacing_curseur").setAttribute("width" , 5 * espace_lettre )
	svgdoc.getElementById("word-spacing_curseur").setAttribute("width" , 5 * espace_mot )
	svgdoc.getElementById("kerning_curseur").setAttribute("width" , 5 * espace )
	var famille = -1
	for (var i = 0 ; i < nb_fonts ; i ++)
		if (police == list_fonts[i])
			famille = i
	if (famille >= 0)
	{
		svgdoc.getElementById("language_actif").setAttribute("font-family",list_fonts[famille])
		svgdoc.getElementById("language_actif").firstChild.data = list_fonts[famille]
	}
}

function check_texte_property(property,value,x_coche)
{
	var etiq = active_field.substring(0 , 4) + "rect" + active_field.substring(4 , active_field.length)
	var test = svgdoc.getElementById(etiq)
	test.setAttribute(property , value)
	svgdoc.getElementById(property).setAttribute("cx" , x_coche)
	if (showed_property == "field")
			refresh_properties(active_field,"all",true)
	else
		show_actif(active_field)
}	

function move_text_curseur(evt,property, max)
{
	if (!clicked2)
		return
	if (ASV == 6)
	{
		var matrix = svgdoc.getElementById("txt_bkground").getScreenCTM().inverse()
		xm = evt.clientX * matrix.a + evt.clientY * matrix.c + matrix.e 
	}
	else
	{
		var matrix = svgdoc.getElementById(prefixe_tool).getCTM().inverse()
		var xm1 = coordo_x(evt.clientX) 
		var ym1 = coordo_y(evt.clientY)
		xm = xm1 * matrix.a + ym1 * matrix.c + matrix.e
	}
	if (xm < 100)
		xm = 100
	if (xm > 200)
		xm = 200
	svgdoc.getElementById(property + "_curseur").setAttribute("width" , xm - 100)
	var value = (xm - 100) * max / 100
	var etiq = active_field.substring(0 , 4) + "rect" + active_field.substring(4 , active_field.length)
	var test = svgdoc.getElementById(etiq)
	test.setAttribute(property , value.toString())
	if (showed_property == "field")
			refresh_properties(active_field,"all",true)
	else
		show_actif(active_field)
}

function hide_show_scroll()
{
	var visible = svgdoc.getElementById("scroll_language").getAttribute("visibility")
	if (visible == "hidden")
		svgdoc.getElementById("scroll_language").setAttribute("visibility","visible")
	else
		svgdoc.getElementById("scroll_language").setAttribute("visibility","hidden")
}

function callbackLG(data)
{
if (!data.success) 
	alert("Ne peut ouvrir fonts ...")
else
	{
		list_fonts = data.content.split("\n")
		nb_fonts = list_fonts.length - 1
		make_list_fonts()
	}
}

function make_list_fonts()
{
	svgdoc.getElementById("template_visible").setAttribute("y",0)
	svgdoc.getElementById("list_visible").setAttribute("transform","translate(165,265)")
	svgdoc.getElementById("template_cursor").setAttribute("y",280)
	var ou = svgdoc.getElementById("scroll_templates")
	for (var i = 0 ; i < nb_fonts ; i++)
	{
		var node = svgdoc.createElement("text")
		node.setAttribute("x",20)
		node.setAttribute("y",13 + 20 * i)
		node.setAttribute("font-size","12")
		node.setAttribute("font-family",list_fonts[i])
		var texte = svgdoc.createTextNode(list_fonts[i])
		node.appendChild(texte)
		ou.appendChild(node)
	}
	decale_templates = 0
	template_click = false
	svgdoc.getElementById("language_actif").setAttribute("font-family",list_fonts[0])
	svgdoc.getElementById("language_actif").firstChild.data = list_fonts[0]
	initialise_texte()	
}

function template_inverse(evt)
{
 	if (ASV == 6)
	{
		var matrix = svgdoc.getElementById("txt_bkground").getScreenCTM().inverse()
		ym = evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f 
	}
	else
	{
		var matrix = svgdoc.getElementById(prefixe_tool).getCTM().inverse()
		var xm1 = coordo_x(evt.clientX) 
		var ym1 = coordo_y(evt.clientY)
		ym = xm1 * matrix.b + ym1 * matrix.d + matrix.f
	}
 	var sous_menu = Math.floor((ym - 45) / 20);
	if ((sous_menu >= 0)&&(sous_menu < 6))
	{
		objet=svgdoc.getElementById("inverse_template")
		objet.setAttribute("y",265 + 20 * sous_menu)
	}
}

function choose_template(evt)
{
 	if (ASV == 6)
	{
		var matrix = svgdoc.getElementById("txt_bkground").getScreenCTM().inverse()
		ym = evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f 
	}
	else
	{
		var matrix = svgdoc.getElementById(prefixe_tool).getCTM().inverse()
		var xm1 = coordo_x(evt.clientX) 
		var ym1 = coordo_y(evt.clientY)
		ym = xm1 * matrix.b + ym1 * matrix.d + matrix.f
	}
 	var sous_menu = Math.floor((ym - 45) / 20);
	if ((sous_menu >= 0)&&(sous_menu < 6))
	{
	   var	example_chosen = sous_menu + decale_templates
		if (example_chosen < nb_fonts)
		{
			svgdoc.getElementById("language_actif").setAttribute("font-family",list_fonts[example_chosen])
			svgdoc.getElementById("language_actif").firstChild.data = list_fonts[example_chosen]
			var etiq = active_field.substring(0 , 4) + "rect" + active_field.substring(4 , active_field.length)
			var test = svgdoc.getElementById(etiq)
			test.setAttribute("font-family" , list_fonts[example_chosen])
			if (showed_property == "field")
				refresh_properties(active_field,"all",true)
			else
				show_actif(active_field)
		}
	}
	svgdoc.getElementById("scroll_language").setAttribute("visibility","hidden")
}

function decale_template(step)
{
	if (nb_fonts < 7)
		return
	decale_templates = decale_templates + parseInt(step)
	if (decale_templates < 0)
		decale_templates = 0
	if (decale_templates > nb_fonts - 6)
		decale_templates = nb_fonts - 6
	svgdoc.getElementById("template_visible").setAttribute("y",20 * decale_templates)
	svgdoc.getElementById("list_visible").setAttribute("transform","translate(165," + ( 265 - 20 * decale_templates) + ")")
	svgdoc.getElementById("template_cursor").setAttribute("y",280 + decale_templates * 75 / (nb_fonts - 6))
}

function template_scroll(evt)
{
	if ((!template_click) || (nb_fonts < 7))
		return
	if (ASV == 6)
	{
		var matrix = svgdoc.getElementById("txt_bkground").getScreenCTM().inverse()
		ym = evt.clientX * matrix.b + evt.clientY * matrix.d + matrix.f - 67
	}
	else
	{
		var matrix = svgdoc.getElementById(prefixe_tool).getCTM().inverse()
		var xm1 = coordo_x(evt.clientX) 
		var ym1 = coordo_y(evt.clientY)
		ym = xm1 * matrix.b + ym1 * matrix.d + matrix.f - 67
	}
  	decale_templates = Math.round(ym * (nb_fonts - 6)/75);
	if (decale_templates < 0)
		decale_templates = 0
	if (decale_templates > nb_fonts - 6)
		decale_templates = nb_fonts - 6
	svgdoc.getElementById("template_visible").setAttribute("y",20 * decale_templates)
	svgdoc.getElementById("list_visible").setAttribute("transform","translate(165," + ( 265 - 20 * decale_templates) + ")")
	if (ym < 0)
		ym = 0
	if (ym > 75)
		ym = 75
	svgdoc.getElementById("template_cursor").setAttribute("y",280 + ym)
}

function put_on_path()
{
	if (active_field.indexOf("text") != 0)
	{
		add_alert("svg/alert.svg","outil2",dialog[48] + "\n" + dialog[49] + "\n" + dialog[50])
		return
	}
	old_acte = "bouge"
	set_curseur("move")
	svgdoc.getElementById("cache").setAttribute("visibility","hidden")
	svgdoc.getElementById("menu_active").setAttribute("x","0")
	acte = "onpath"
}